package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.EditTemplateBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.service.EditTemplateCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.cs_info;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
/**
*设置客服权限模板
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_EditTemplate{
	private static EditTemplateBean edittemplateBean;
	private static EditTemplateCall edittemplateCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置客服权限模板");
	}

	@Before
	public void caseUp() {
		edittemplateBean=new EditTemplateBean();
		edittemplateCall=new EditTemplateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(edittemplateCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditTemplate_001() {
		Logger.start(true,"设置客服权限模板,成功");
		try {
			Integer templateId=1;
			int mchId=GodmchManageCallService.CreateSellerMch();
	        UserCreateBean usercreateBean= DGUserCallService.initCsUsercreateBean();
			int csId=DGUserCallService.UserCreateCall(usercreateBean);
	        GodmchManageCallService.CreateCSCall(mchId, csId, templateId);
	        Logger.comment("创建渠道商客服:"+csId);
	        
			edittemplateBean.setMchId(mchId);
			edittemplateBean.setCsId(csId);
			edittemplateBean.setTemplateId(2);
			edittemplateCall.setData(edittemplateBean);
			edittemplateCall.callService();
			Logger.verifyEquals("200", edittemplateCall.getString("status"), "验证status");
			cs_info csi = new DefGodMchWapper().selectCsInfo(mchId, csId).get(0);
			Logger.verifyEquals(edittemplateBean.getTemplateId(), csi.getTempldateId(), "验证TempldateId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditTemplate_002() {
		Logger.start(true,"设置客服权限模板,验证商户id和客服id同时存在,但是关系不匹配-客服id不是当前商户下,返回失败");
		try {
			Integer templateId=1;
			int mchId=GodmchManageCallService.CreateSellerMch();
	        UserCreateBean usercreateBean= DGUserCallService.initCsUsercreateBean();
			int csId=DGUserCallService.UserCreateCall(usercreateBean);
	        GodmchManageCallService.CreateCSCall(mchId, csId, templateId);
	        Logger.comment("创建渠道商客服:"+csId);
	        int mchId2=GodmchManageCallService.CreateSellerMch();
			edittemplateBean.setMchId(mchId2);
			edittemplateBean.setCsId(csId);
			edittemplateBean.setTemplateId(2);
			edittemplateCall.setData(edittemplateBean);
			edittemplateCall.callService();
			Logger.verifyEquals("5023", edittemplateCall.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditTemplate_003() {
		Logger.start(true,"设置客服权限模板,验证商户id不存在,返回失败");
		try {
			Integer templateId=1;
			int mchId=GodmchManageCallService.CreateSellerMch();
	        UserCreateBean usercreateBean= DGUserCallService.initCsUsercreateBean();
			int csId=DGUserCallService.UserCreateCall(usercreateBean);
	        GodmchManageCallService.CreateCSCall(mchId, csId, templateId);
	        Logger.comment("创建渠道商客服:"+csId);
			edittemplateBean.setMchId(1);
			edittemplateBean.setCsId(csId);
			edittemplateBean.setTemplateId(2);
			edittemplateCall.setData(edittemplateBean);
			edittemplateCall.callService();
			Logger.verifyEquals("5023", edittemplateCall.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditTemplate_004() {
		Logger.start(true,"设置客服权限模板,验证客服id不存在,返回失败");
		try {
			Integer templateId=1;
			int mchId=GodmchManageCallService.CreateSellerMch();
	        UserCreateBean usercreateBean= DGUserCallService.initCsUsercreateBean();
			int csId=DGUserCallService.UserCreateCall(usercreateBean);
	        GodmchManageCallService.CreateCSCall(mchId, csId, templateId);
	        Logger.comment("创建渠道商客服:"+csId);
			edittemplateBean.setMchId(mchId);
			edittemplateBean.setCsId(1);
			edittemplateBean.setTemplateId(2);
			edittemplateCall.setData(edittemplateBean);
			edittemplateCall.callService();
			Logger.verifyEquals("5023", edittemplateCall.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditTemplate_005() {
		Logger.start(true,"设置客服权限模板,验证模板id不存在,返回失败");
		try {
			Integer templateId=1;
			int mchId=GodmchManageCallService.CreateSellerMch();
	        UserCreateBean usercreateBean= DGUserCallService.initCsUsercreateBean();
			int csId=DGUserCallService.UserCreateCall(usercreateBean);
	        GodmchManageCallService.CreateCSCall(mchId, csId, templateId);
	        Logger.comment("创建渠道商客服:"+csId);
			edittemplateBean.setMchId(mchId);
			edittemplateBean.setCsId(csId);
			edittemplateBean.setTemplateId(-1);
			edittemplateCall.setData(edittemplateBean);
			edittemplateCall.callService();
			Logger.verifyEquals("5022", edittemplateCall.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditTemplate_006() {
		Logger.start(true,"设置客服权限模板,验证商户id为空,返回失败");
		try {
			edittemplateBean.setMchId(null);
			edittemplateBean.setCsId(1);
			edittemplateBean.setTemplateId(1);
			edittemplateCall.setData(edittemplateBean);
			edittemplateCall.callService();
			Logger.verifyEquals("4001", edittemplateCall.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditTemplate_007() {
		Logger.start(true,"设置客服权限模板,验证客服id为空,返回失败");
		try {
			edittemplateBean.setMchId(1);
			edittemplateBean.setCsId(null);
			edittemplateBean.setTemplateId(1);
			edittemplateCall.setData(edittemplateBean);
			edittemplateCall.callService();
			Logger.verifyEquals("4001", edittemplateCall.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_EditTemplate_008() {
		Logger.start(true,"设置客服权限模板,验证模板id为空,返回失败");
		try {
			edittemplateBean.setMchId(1);
			edittemplateBean.setCsId(1);
			edittemplateBean.setTemplateId(null);
			edittemplateCall.setData(edittemplateBean);
			edittemplateCall.callService();
			Logger.verifyEquals("4001", edittemplateCall.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}